// <!-- 折线图 -->
<style lang="stylus" scoped>
.multipless2
  height 100px
  background-size 100% 100%
  .main
    width 100%
    height calc(100% - 100px)
    margin-top -15px
</style>


<template>
<div class="multipless2">
  <p class='titlemultipless2' style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>刑满释放人员刑期分布</p>
  <div class="main"></div>
</div>

</template>

<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  watch: {
    too(val, oldVal) {
      console.log("watch=", val, oldVal)
    }
  },
  methods: {
    _init() {
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.multipless2 .main'))
    this.myChart.on("click", function(params) {
      // localStorage.setItem('areaname', params.name)
      // location.href = "/pingdingshan/vue/#/anzhibang3?areaname=" + params.name;
    })
    var areaname = localStorage.getItem('areaname');
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/mapData?name=' + areaname).then((res) => {
    // axios.get('static/data/Data2.json').then((res) => {
      if (res) {
        var arr = [];
        var countarr1 = [];
        var countarr2 = [];
        var countarr3 = [];
        $(res.data).each(function() {
          if (this.name !== areaname) {
            arr[arr.length] = this.name;
            var arr1 = this.anzhiprisontermcount.split(",");
            countarr1[countarr1.length] = arr1[0];
            countarr2[countarr2.length] = arr1[1];
            countarr3[countarr3.length] = arr1[2];
          }
        })
        localStorage.setItem('areadata', JSON.stringify(res.data));
        this.myChart.setOption({
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {
            data: ['3年以下', '3年-7年', '7年以上']
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#00AA5E'
                }
              },
              axisLabel: {
                rotate: 50,
                textStyle: {
                  color: 'rgba(11, 144, 60, 1)',
                  fontWeight: 'bold',
                  fontSize: '10'
                }
              },
              type: 'category',
              data: arr,
              splitLine: {
                show: false
              }
            }
          ],
          yAxis: [
            {
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#00AA5E'
                }
              },
              axisLabel: {
                textStyle: {
                  color: 'rgba(11, 144, 60, 1)',
                  fontWeight: 'bold',
                  fontSize: '10'
                }
              },
              type: 'value',
              splitLine: {
                show: false
              }
            }
          ],
          series: [
            {
              name: '3年以下',
              type: 'bar',
              data: countarr1,
              itemStyle: {
                normal: {
                  barBorderRadius: [5, 5, 0, 0],
                  label: {
                    formatter: function (params) {
                      if (params.value > 0) {
                        return params.value;
                      } else {
                        return "";
                      }
                    },
                    show: true,
                    color: '#00AA5E',
                    position: 'top',
                    fontWeight: 'bold'
                  }
                }
              }
            },
            {
              name: '3年-7年',
              type: 'bar',
              data: countarr2,
              itemStyle: {
                normal: {
                  barBorderRadius: [5, 5, 0, 0],
                  label: {
                    formatter: function (params) {
                      if (params.value > 0) {
                        return params.value;
                      } else {
                        return "";
                      }
                    },
                    show: true,
                    color: '#00AA5E',
                    position: 'top',
                    fontWeight: 'bold'
                  }
                }
              }
            },
            {
              name: '7年以上',
              type: 'bar',
              data: countarr3,
              itemStyle: {
                normal: {
                  barBorderRadius: [5, 5, 0, 0],
                  label: {
                    formatter: function (params) {
                      if (params.value > 0) {
                        return params.value;
                      } else {
                        return "";
                      }
                    },
                    show: true,
                    color: '#00AA5E',
                    position: 'top',
                    fontWeight: 'bold'
                  }
                }
              }
            }
          ]
        });
        this._init()
      }
    });
  }
}
</script>
